/*
 * @Author: zingpp
 * @Date: 2025-06-19 17:44:45
 * @LastEditors: zingpp
 * @LastEditTime: 2025-06-20 16:49:07
 * @FilePath: \cool-server\src\main.ts
 * @Description:
 *
 * Copyright (c) 2025 by 用户/公司名, All Rights Reserved.
 */
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { HttpExceptionFilter } from './filters/http-exception.filter';
import { WinstonModule } from 'nest-winston';
import { winstonConfig } from './common/logger';
import { AuditLogInterceptor } from './common/audit-log.interceptor';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: WinstonModule.createLogger(winstonConfig),
  });

  // 启用全局 CORS 跨域
  app.enableCors();

  // 注册全局异常过滤器
  app.useGlobalFilters(new HttpExceptionFilter());

  // 注册全局审计日志拦截器
  app.useGlobalInterceptors(new AuditLogInterceptor());

  // Swagger 配置
  const config = new DocumentBuilder()
    .setTitle('Cool Server API')
    .setDescription('API 文档')
    .setVersion('1.0')
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api-docs', app, document);

  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
